get_template_part_{$slug}
Action HookDescription
Fires before the specified template part file is loaded. The dynamic portion of the hook name, `$slug`, refers to the slug name for the generic template part.Hook Information
File Location |
wp-includes/general-template.php
View on GitHub
|
Hook Type | Action |
Line Number | 182 |
Hook Parameters
Type | Name | Description |
---|---|---|
string
|
$slug
|
The slug name for the generic template. |
string|null
|
$name
|
The name of the specialized template or null if there is none. |
array
|
$args
|
Additional arguments passed to the template. |
Usage Examples
Basic Usage
<?php
// Hook into get_template_part_{$slug}
add_action('get_template_part_{$slug}', 'my_custom_function', 10, 3);
function my_custom_function($slug, $name, $args) {
// Your custom code here
}
Source Code Context
wp-includes/general-template.php:182
- How this hook is used in WordPress core
<?php
177 * @param string $slug The slug name for the generic template.
178 * @param string|null $name The name of the specialized template
179 * or null if there is none.
180 * @param array $args Additional arguments passed to the template.
181 */
182 do_action( "get_template_part_{$slug}", $slug, $name, $args );
183
184 $templates = array();
185 $name = (string) $name;
186 if ( '' !== $name ) {
187 $templates[] = "{$slug}-{$name}.php";
PHP Documentation
<?php
/**
* Fires before the specified template part file is loaded.
*
* The dynamic portion of the hook name, `$slug`, refers to the slug name
* for the generic template part.
*
* @since 3.0.0
* @since 5.5.0 The `$args` parameter was added.
*
* @param string $slug The slug name for the generic template.
* @param string|null $name The name of the specialized template
* or null if there is none.
* @param array $args Additional arguments passed to the template.
*/
Quick Info
- Hook Type: Action
- Parameters: 3
- File: wp-includes/general-template.php
Related Hooks
Related hooks will be displayed here in future updates.